//
//  UserEditProfessionalCell.m
//  CheekiOS
//
//  Created by mac on 2017/7/5.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserEditProfessionalCell.h"

@interface UserEditProfessionalCell ()

@property (nonatomic, strong)NSMutableArray *buttonArray;

@end

@implementation UserEditProfessionalCell

+(instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
    
    static NSString *UserEditProfessionalCellIdent = @"UserEditProfessionalCellIdent";
    
    
    UserEditProfessionalCell *cell = [tableView dequeueReusableCellWithIdentifier:UserEditProfessionalCellIdent];
    if (!cell) {
        cell = [[UserEditProfessionalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UserEditProfessionalCellIdent];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _buttonArray= [NSMutableArray array];
    }
    return self;
}


-(void)setTitleArr:(NSArray *)titleArr{

    
    CGFloat buttonY = 15;
    CGFloat buttonY2 = 15;
    
    CGFloat buttonX = 15;
    
    CGFloat buttonK = 7.5;
    
    CGFloat buttonH = 40;
    
    CGFloat buttonW = (KScreenWidth-45)/3;
    
    for (int i = 0; i < titleArr.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(buttonX+(i%3*(buttonW+buttonK)),buttonY+(i/3*(buttonY2+buttonH+buttonY)), buttonW, buttonH);
        button.tag = i;
        [button setTitle:titleArr[i] forState:UIControlStateNormal];
        button.titleLabel.font = FontP(15);
        button.backgroundColor = Theme_Color_White;
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button.layer setMasksToBounds:YES];//设置按钮的圆角半径不会被遮挡
        
        [button.layer setCornerRadius:20];
        
        [button.layer setBorderWidth:1];//设置边界的宽度
        
        //设置按钮的边界颜色
        [button.layer setBorderColor:ColorI(0xf6f6f6).CGColor];
        
        [button addTarget:self action:@selector(buttonActionClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [_buttonArray addObject:button];
        
        [self addSubview:button];
        
    }


}

- (void)buttonActionClick:(UIButton *)button{
    for (UIButton * btn in _buttonArray) {
        if (btn != button) {
            btn.selected = NO;
            btn.backgroundColor = Theme_Color_White;

        }else{
            btn.selected = YES;
            btn.backgroundColor = Colorbackground;
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(buttonActionClick:)]) {
        [self.delegate buttonActionClick:button];
    }
}


@end
